﻿using B.S.Data.MES.API.Applications.BaseData.Command.CheJianCommand;
using B.S.Domain.BasicData.Factory_modeling.shop_management;
using B.S.Infratrctrue;
using B.S.Requst;
using MediatR;

namespace B.S.Data.MES.API.Applications.BaseData.CommandHandlers.ChejianCommandHandlers
{
    public class PLDeleCheJIanCommandHandlers : IRequestHandler<PLDeleCheJianCommand, APIRequst<int>>
    {
        private readonly IBaseRepository<shop_management> shopRepository;

        public PLDeleCheJIanCommandHandlers(IBaseRepository<shop_management> shopRepository)
        {
            this.shopRepository = shopRepository;
        }

        public async Task<APIRequst<int>> Handle(PLDeleCheJianCommand request, CancellationToken cancellationToken)
        {
            APIRequst<int> requst = new APIRequst<int>();
            requst.Code = RequstCode.成功;
            requst.Msg = RequstCode.成功.ToString();
            var path = shopRepository.GetAll().Where(a => request.Ids.Contains(a.Workid)).ToList();
            foreach(var item in path)
            {
                item.isDel = true;
            }
            await shopRepository.UpdateRange(path);
            return await Task.FromResult(requst);
        }
    }
}
